package com.zsrt.java.day20161223.wrl.t03;

import java.util.Scanner;

public class Pay {
	public static void main(String[] args) {
		String name = "";		//商品名称
		float price = 0;		//商品价格
		int proNo;				//商品编号
		
		int count;			//购入数量
		double discount = 0.8;
		double total = 0;	//购买总金额
		double finalPay = 0;//打折后需付款
		double payment;		//实际交付金额
		double returnMoney;	//找钱
		
		/*打印产品清单*/
		System.out.println("-----------------------------------------");
		System.out.println("请选择商品编号：\n");
		System.out.println("1.巧克力    2.红牛    3.娃哈哈");
		System.out.println("-----------------------------------------");
		Scanner input = new Scanner(System.in);
		String answer = "y";
		while("y".equals(answer)){
			System.out.println("请输入商品编号：");
			proNo = input.nextInt();
			System.out.println("请输入购买数量：");
			count = input.nextInt();
			switch (proNo) {
			case 1:
				name  = "巧克力";
				price = 10.8f;
				break;
			case 2:
				name  = "红牛";
				price = 5.5f;
				break;
			case 3:
				name  = "娃哈哈";
				price = 3.5f;
				break;
			}
			System.out.println(name+"\t￥"+price+"\t\t￥"+price*count);
			total = total + price * count;
			System.out.println("\n是否继续（y/n）");
			answer = input.next();
		}
		
		/*计算消费总金额*/
		finalPay = total * discount;
		
		/*打印购物小票*/
		System.out.println("折扣："+discount);//修改
		System.out.println("金额总计：\t￥"+finalPay);//修改
		System.out.println("实际交付：\t￥");//修改
		payment = input.nextDouble();	//新增代码
		returnMoney = payment - finalPay;	//计算找钱
		System.out.println("找钱\t￥"+returnMoney);
		input.close();
	}

}
